//! 全局任务处理

use sgs_runtime::{
    executor::{Controller, Event, Global, Viewer},
    preclude::Delegate,
};

/// 全局事件委托器
///
/// 启动初始化委托器
///
/// 处理所有 [Global] 事件
pub struct GlobalDelegator;

impl std::fmt::Debug for GlobalDelegator {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "sgs_pkg_std::GlobalDelegator 全局事件委托器")
    }
}

impl Delegate for GlobalDelegator {
    fn delegate(
        &self,
        event: &Event,
        viewer: &Viewer,
        controller: &mut Controller,
    ) -> Option<Event> {
        match event {
            Event::Global(event) => delegate(event, viewer, controller),
            _ => None,
        }
    }
}

/// 全局任务处理
fn delegate(event: &Global, _viewer: &Viewer, _controller: &mut Controller) -> Option<Event> {
    match event {
        _ => None,
    }
}
